//服务器的入口文件
//1.创建koa的实例对象
const koa =require("koa")
const app =new koa()
//2.绑定第一层中间件
const respDurationMiddleware = require("./middleware/koa_response_duration")
app.use(respDurationMiddleware)
//绑定第二层中间件
const respHeader =require("./middleware/koa_response_header")
app.use(respHeader)
//绑定第三层中间件
const respDataMiddleware = require("./middleware/koa_respone_data")
app.use(respDataMiddleware)
//3.绑定端口号 8888
app.listen(8888)
//引入websocket
const websocket = require("ws")
//创建webscoket 对象
 const wss = new websocket.Server({
    port:8889
})
//对客户端的连接对象进行监听
//client 代表客户端的连接websocket对象
wss.on("connection",(client)=>{
        console.log("连接成功");
     client.on("message",(msg)=>{
         console.log("客户端给服务器发生数据了"+msg);
         client.send("hello,webscoket")
     })   
})